package com.xu.ThrreadPool;

import java.util.Random;
import java.util.concurrent.*;

/**
 * 演示有返回值的线程池
 *
 * 结论：submit 它可以执行有返回值的任务或者是没有返回值的任务
 */
public class ThreadPoolDemo2 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        Future<Integer> result = executorService.submit(() -> {
            int num = new Random().nextInt();
            System.out.println("生成随机数" + num);
            return num;
        });
        System.out.println("得到线程池返回结果"+result.get());
    }
}
